package com.practice.designMode.responsibilityChain.validation;

import com.practice.designMode.responsibilityChain.exception.ValidatorException;

public class LengthValidatorHandler implements ValidatorHandler{

    private final Integer length;

    public LengthValidatorHandler(Integer length) {
        this.length = length;
    }

    @Override
    public void validate(Object bean,ValidatorContext validatorContext) throws ValidatorException {
        if (bean instanceof String str) {
            if(str.length() != length){
                validatorContext.appendError("LengthValidatorHandler: " + str +" length is not equal to " + length);
            }
        }
    }
}
